package homewoek1月4号.demo3.d4;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo1 {
    public static void main(String[] args) throws IOException {
        Map<String, String> map = jiexi("src/czxy/com/demo3/d4/c.txt");
        for (Map.Entry<String, String> s : map.entrySet()) {
            System.out.println(s.getKey()+":"+s.getValue());
        }
    }
    public static Map<String,String> jiexi(String s) throws IOException {
        HashMap<String, String> map = new HashMap<>();
        List<String> list = FileUtils.readLines(new File(s));
        for (String str : list) {
            char[] arr = str.toCharArray();
            for (int i = 0; i < arr.length; i++) {
                String a=arr[i]+"";
                if (map.containsKey(arr[i]+"")){
                    map.put(a,(Integer.parseInt(map.get(a))+1)+"");
                }else {
                    map.put(a,"1");
                }
            }
        }
        return map;
    }
}
